/*
 *  Copyright 2010 INFN - APE group
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#pragma once

#include <cuos/config.h>

#include <cuqu/utils.h>

// GPU code debugging aids
#define cuos_error(FMT, ARGS...) cudaPrintf(FMT, ##ARGS)

// enable trace prints
#if CUOS_ENABLE_TRACING
#define cuos_trace(FMT, ARGS...) cudaPrintf(FMT, ##ARGS)
#else
#define cuos_trace(FMT, ARGS...) do { } while(0)
#endif

// CPU code debugging aids
#define cuosError(FMT, ARGS...) do { fprintf(stderr, "%s(%d): " FMT, __FILE__, __LINE__, ##ARGS); fflush(stderr); } while(0)

#define cuosErrorC(CNT, FMT, ARGS...) do {      \
        static int c = 0;                       \
        if(++c < (CNT))                         \
            cuosError(FMT, ##ARGS);             \
    } while(0)

#if CUOS_ENABLE_TRACING
#define cuosTrace(FMT, ARGS...) do { fprintf(stderr, "%s(%d): " FMT, __FILE__, __LINE__, ##ARGS); fflush(stderr); } while(0)
#else
#define cuosTrace(FMT, ARGS...) do { } while(0)
#endif

#define cuosTraceC(CNT, FMT, ARGS...) do {      \
        static int c = 0;                       \
        if(++c < (CNT))                         \
            cuosTrace(FMT, ##ARGS);             \
    } while(0)

/*
 * Code taken from NVIDIA Computing SDK
 */

#define cuosDrvSafeCall(err)       cuquDrvSafeCall(err)
#define cuosSafeCall(err)          cuquSafeCall(err)
#define cuosCheckMsg(msg)          cuquCheckMsg(msg)

/*
 * Local variables:
 *  mode: c++
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 *  indent-tabs-mode: nil
 * End:
 */
